﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Lending.RMF.AutoProcessService.Interface;

namespace AutoDataPump
{
    public class Executor : IAutoProcess
    {
        public Executor()
        {
            Interval = 12;
        }

        public override void Execute(DateTime handleTime, object param)
        {
            if (handleTime.Hour == 8) //早上八点执行
            {
                try
                {
                    LogHelper.Write(CommonLogger.AutoDataPump, LogLevel.Info,
                        String.Format("AutoDataPump 于{0}开始执行。", handleTime.ToString()));

                    HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.yaojianzhi.com/home/pump");
                    request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
                    request.Accept = "*/*";
                    request.KeepAlive = true;
                    request.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");

                    System.Net.HttpWebResponse response = null;
                    response = (System.Net.HttpWebResponse)request.GetResponse();
                    LogHelper.Write(CommonLogger.AutoDataPump, LogLevel.Info,
                        String.Format("执行结果，StatusCode：" + response.StatusCode.ToString()));
                }
                catch (Exception e)
                {
                    LogHelper.Write(CommonLogger.AutoDataPump, LogLevel.Error, e);
                }
            }
        }
    }
}
